<?php

require_once dirname(__FILE__).'/../lib/mailboxGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/mailboxGeneratorHelper.class.php';

/**
 * mailbox actions.
 *
 * @package    sf_sandbox
 * @subpackage mailbox
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class mailboxActions extends autoMailboxActions
{

      protected function buildCriteria()
  {
    if (is_null($this->filters))
    {
      $this->filters = $this->configuration->getFilterForm($this->getFilters());
    }

    $criteria = $this->filters->buildCriteria($this->getFilters());

    $this->addSortCriteria($criteria);

    $event = $this->dispatcher->filter(new sfEvent($this, 'admin.build_criteria'), $criteria);
    $criteria = $event->getReturnValue();

    if($this->getUser()->hasCredential('partner') and !$this->getUser()->isSuperadmin() )
    {
        //$criteria->add(sfGuardUserPeer::PARTNER_ID,$this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
        
        //$criteria->add(MailboxPeer::PARTNER_ID, $this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
        
        //$crit1=$criteria->getNewCriterion(MailboxPeer::FROM_PARTNER_ID, $this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
        //$crit2=$criteria->getNewCriterion(MailboxPeer::TO_PARTNER_ID, $this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
        //$crit1->addOr($crit2);
        //$criteria->add($crit1);
        $criteria->add(MailboxPeer::TO_PARTNER_ID, $this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
                
    }
    return $criteria;
  }

}
